package org.exmaple.springframework.beans.factory.support;

import org.exmaple.springframework.beans.BeansException;
import org.exmaple.springframework.beans.factory.config.BeanDefinition;

/**
 * @author DeYou
 * @date 2022/10/26
 */
public abstract  class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{
    /**
     * 创建Bean 如果没有bean 就创建Bean，并把bean对象加入容器。返回bean对象
     * @param name
     * @param beanDefinition
     * @return
     * @throws BeansException
     */
    @Override
    protected Object createBean(String name, BeanDefinition beanDefinition) throws BeansException {
        Object bean;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException( e );
        } catch (IllegalAccessException e) {
            throw new RuntimeException( e );
        }
        //注册到单例子bean 容器
        registerSingleton( name,bean );
        return bean;
    }
}